#include "coomm.hpp"

int main()
{
    // 1 不创建共享内存，而是获取其id用于关联
    key_t k = getKey();
    printf("0x%x\n", k);
    int shmid = getShm(k); // 获取创建的共享内存块的id值
    printf("clent get shmid:%d\n", shmid);

    // 2 关联进程和共享内存
    char *start = (char *)attachShm(shmid);
    printf("client attch success, address start: %p\n", start);

    const char *mesage = "hello server, 我是另一个进程，我正在和你通信!";
    pid_t id = getpid();
    int cnt = 1;
    // 3 使用
    while (true)
    {
        //管道,char buffer,snprintf[buffer..],write(pipefd,buffer...)
        sleep(1);
        snprintf(start, MAXSZIE, "%s[client pid:%d][消息编号:%d]", mesage, id, cnt++);
    }

    // 4 去关联共享内存和其虚拟地址空间，删除让server去做
    detachShm(start);
    printf("client delete attch success!\n");
    return 0;
}